package com.animee.tally.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

/*
* 记录页面的ViewPager的适配器
* */
public class RecordPagerAdapter extends FragmentPagerAdapter {
    List<Fragment>fragmentList;     //ViewPager要展示的数据源
    String [] titles = {"支出","收入"};    //标题数组
    public RecordPagerAdapter(@NonNull FragmentManager fm,List<Fragment>fragmentList) {
        super(fm);
        this.fragmentList = fragmentList;
    }
//    返回指定位置的fragment对象
    @NonNull
    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }
//   返回viewpager加载的页数
    @Override
    public int getCount() {
        return fragmentList.size();
    }
//  返回指定位置对应的标题
    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}
